package main

//67  穷举法查10万以内的数

import (
	"fmt"
	"time"
)

func main() {
	fmt.Println("(go Language)  Please wait for some minutes,will found Next Fn(n) = n ,the n is:")
	n := 1
	count := 0
	pos := 0
	aa := make(map[int]int)
	t := time.Now()
	for n = 1; n <= 100000; n++ {
		pos = Fn(n)
		aa[n] = pos
		if n == pos {
			count++
			fmt.Println("n is :", n, " Fn(n) is :", pos)
			if (count > 1) {
				break
			}
		}
	}
	fmt.Println("time is :", time.Now().Sub(t).String())
	fmt.Println(n, " stop")
}

func Fn(n int) int {
	var total int
	for i := 0; i <= n; i++ {
		total += Count(i)
	}
	return total
}

func Count(n int) int {
	var num int
	for t := n; t >= 1; t = t / 10 {
		if (t%10 == 1) {
			num++
		}
	}
	return num
}
